home *** CD-ROM | disk | FTP | other *** search
/ L' Effet Pommier 3 / L'Effet Pommier - Volume 03.iso / Programmation / Gooey1.3.1 / C Templates / mmModelessDialog.c < prev    next >
Text File  |  1994-04-14  |  23KB  |  623 lines

  1. $$Loop ModelessDialogs
  2. $$Message MM Modeless Dialog, mm:mmMD_$Worksheet.name$.c
  3.  
  4. $$File mm:mmMD_$Worksheet.name$.c
  5. /*  mmMD_$Worksheet.name$                                 Handle this dialog */
  6. /*  $CopyRight$ */
  7.  
  8. /*    File name:  mmMD_$Worksheet.name$.c
  9.     Function:  Handle this modeless dialog.
  10.  
  11.     This dialog is called when:
  12.  
  13.     History: $Date$ Original by $Author$
  14.  
  15. */
  16.  
  17. /* ======================================================= */
  18. /* ======================================================= */
  19.  
  20. #include "mmCommon$Prototype.name$.h"    /* Common */
  21. #include "Common$Prototype.name$.h"        /* Common */
  22.  
  23. #include "$Worksheet.name$.h"
  24.  
  25. /* ======================================================= */
  26. /* ======================================================= */
  27.  
  28. /* Routine: Init_$Worksheet.name$ */
  29. /* Purpose: This procedures purpose is to set the window pointer to nil, */
  30. /* this is used to tell the other routines */
  31.  
  32. void Init_$Worksheet.name$(void)
  33. {
  34. Rect    tempRect;                                    /* Temporary rectangle */
  35. short    DType;                                    /* Type of dialog item */
  36. short    Index;                                    /* For looping */
  37. Handle    DItem;                                    /* Handle to the dialog item */
  38. ControlHandle    CItem, CTempItem;                    /* Control handle */
  39. Str255    sTemp;                                    /* Get text entered, temp holding */
  40. short    itemHit;                                    /* Get selection */
  41. short    temp;                                        /* Get selection, temp holding */
  42.  
  43.  
  44. Rec_$Worksheet.name$.theDialog = nil;                    /* Initialize to say that the dialog is not yet active */
  45.  
  46. $$Loop Control.type = Button
  47. Rec_$Worksheet.name$.Enable_$Control.name$ = $Control.Active$;            /* Button */
  48. $$EndLoop
  49. $$Loop Control.type = HotRect
  50. $$if Control.HotSpot
  51. Rec_$Worksheet.name$.Enable_$Control.name$ = $Control.Active$;            /* HotSpot */
  52. $$endif
  53. $$EndLoop
  54. $$Loop Control.type = Checkbox
  55. Rec_$Worksheet.name$.Enable_$Control.name$ = $Control.Active$;            /* Checkbox */
  56. $$if Control.Selected
  57. Rec_$Worksheet.name$.Value_$Control.name$ = 1;
  58. $$endif
  59. $$if Control.Unselected
  60. Rec_$Worksheet.name$.Value_$Control.name$ = 0;
  61. $$endif
  62. $$EndLoop
  63. $$Loop Control.type = Radio
  64. Rec_$Worksheet.name$.Enable_$Control.name$ = $Control.Active$;            /* Radio */
  65. $$if Control.Selected
  66. Rec_$Worksheet.name$.Value_$Control.name$ = 1;
  67. $$endif
  68. $$if Control.Unselected
  69. Rec_$Worksheet.name$.Value_$Control.name$ = 0;
  70. $$endif
  71. $$EndLoop
  72. $$Loop Control.type = ScrollBar
  73. Rec_$Worksheet.name$.Enable_$Control.name$ = $Control.Active$;            /* ScrollBar */
  74. Rec_$Worksheet.name$.Value_$Control.name$ = $Control.ValueScroll$;
  75. $$EndLoop
  76. $$Loop Control.type = Icon
  77. Rec_$Worksheet.name$.Enable_$Control.name$ = $Control.Active$;            /* Icon button */
  78. $$EndLoop
  79. $$Loop Control.type = Sicn
  80. Rec_$Worksheet.name$.Enable_$Control.name$ = $Control.Active$;            /* Sicn button */
  81. $$EndLoop
  82. $$Loop Control.type = Picture
  83. $$if Control.NonGraphic
  84. Rec_$Worksheet.name$.Enable_$Control.name$ = $Control.Active$;            /* Picture button */
  85. $$endif
  86. $$EndLoop
  87. $$Loop Control.type = UButton
  88. Rec_$Worksheet.name$.Enable_$Control.name$ = $Control.Active$;            /* Plugin button */
  89. $$EndLoop
  90. $$Loop Control.type = UToggle
  91. Rec_$Worksheet.name$.Enable_$Control.name$ = $Control.Active$;            /* Plugin toggle */
  92. $$if Control.Selected
  93. Rec_$Worksheet.name$.Value_$Control.name$ = 1;
  94. $$endif
  95. $$if Control.Unselected
  96. Rec_$Worksheet.name$.Value_$Control.name$ = 0;
  97. $$endif
  98. $$EndLoop
  99. $$Loop Control.type = UGauge
  100. Rec_$Worksheet.name$.Enable_$Control.name$ = $Control.Active$;            /* Plugin gauge */
  101. Rec_$Worksheet.name$.Value_$Control.name$ = $Control.ValueScroll$;
  102. $$EndLoop
  103. $$Loop Control.type = Popup
  104. Rec_$Worksheet.name$.Enable_$Control.name$ = $Control.Active$;            /* Popup menu */
  105. Rec_$Worksheet.name$.Value_$Control.name$ = $Control.SelectedID$;
  106. $$EndLoop
  107. $$Loop Control.type = Palette
  108. Rec_$Worksheet.name$.Enable_$Control.name$ = $Control.Active$;            /* Palette */
  109. Rec_$Worksheet.name$.Value_$Control.name$ = $Control.ValueScroll$;
  110. $$EndLoop
  111. $$Loop Control.type = List
  112. Rec_$Worksheet.name$.List_$Control.name$ = nil;                            /* List */
  113. SetRect(&Rec_$Worksheet.name$.ListRect_$Control.name$,$Control.LeftPosition$,$Control.TopPosition$,$Control.RightPosition$,$Control.BottomPosition$);        /* left,top,right,bottom */
  114. $$EndLoop
  115. $$Loop Control.type = EditText
  116. Rec_$Worksheet.name$.TE_$Control.name$ = nil;                            /* Edit Text */
  117. SetRect(&Rec_$Worksheet.name$.TERect_$Control.name$,$Control.LeftPosition$,$Control.TopPosition$,$Control.RightPosition$,$Control.BottomPosition$);        /* left,top,right,bottom */
  118. GetIndString(Rec_$Worksheet.name$.TEStr_$Control.name$,sResD_$Control.name$,1);/*  ...Edit text, default value  */
  119.  
  120. $$EndLoop
  121.  
  122. U_Init_$Worksheet.name$();                            /* Call the user init routine */
  123. }
  124.  
  125. /* ======================================================= */
  126.  
  127. /* Routine: Moved_$Worksheet.name$ */
  128. /* Purpose: We were moved, possibly to another screen and screen depth */
  129.  
  130. void Moved_$Worksheet.name$(Rect *OldRect,WindowPtr theWindow)/* Moved this window */
  131. {
  132. WindowPtr    SavePort;                                /* Place to save the last port */
  133.  
  134.  
  135. if (Rec_$Worksheet.name$.theDialog == theWindow)                /* Only do if the window is us */
  136.     {
  137.     GetPort(&SavePort);                            /* Save the current port */
  138.     SetPort(theWindow);                            /* Set the port to my window */
  139.  
  140.     U_Moved_$Worksheet.name$(theWindow,OldRect);    /* Call user routine when we are moved */
  141.     SetPort(SavePort);                                /* Restore the old port */
  142.     }                                            /* End of IF */
  143. }
  144.  
  145. /* ======================================================= */
  146.  
  147. /* Routine: Update_$Worksheet.name$ */
  148. /* Purpose: This procedures purpose is to refresh this window, update it, */
  149. /* when we are uncovered by another window.  */
  150.  
  151. void Update_$Worksheet.name$(WindowPtr theWindow)
  152. {
  153. GrafPtr    SavedPort;                                /* Save the current port so we can restore to it */
  154. Rect    tempRect;                                    /* Temporary rectangle variable */
  155. Rect    rTempRect;                                    /* Temporary rectangle variable */
  156. short    DType;                                    /* Type of dialog item */
  157. Handle    DItem;                                    /* Handle to the dialog item */
  158. ControlHandle    CItem;                            /* Control handle */
  159. RGBColor    Saved_ForeColor;                        /* Place to save colors */
  160. RGBColor    Saved_BackColor;                        /* Place to save colors */
  161. RGBColor    DrawingColor;                            /* Place to make colors */
  162.  
  163.  
  164. if ((Rec_$Worksheet.name$.theDialog != nil) && (theWindow == Rec_$Worksheet.name$.theDialog))/* Only do if we are the window to update */
  165.     {
  166.     GetPort(&SavedPort);                            /* Get the current port */
  167.     SetPort(theWindow);                            /* Point to our port for drawing in our window */
  168.     if (Has.ColorQD)                                /* See if color QuickDraw is around */
  169.         {
  170.         GetForeColor(&Saved_ForeColor);            /* Save the fore color */
  171.         GetBackColor(&Saved_BackColor);            /* Save the back color */
  172.  
  173.         RGBForeColor(&Black_ForeColor);            /* Set the fore color to Black */
  174.         RGBBackColor(&White_BackColor);            /* Set the back color to White */
  175.         }                                        /* End of IF */
  176.  
  177. $$Loop Control.type = Button
  178. $$if Control.Default
  179.     /* This is the default selection, when RETURN is pressed. */
  180.     HiliteDefaultButton(theWindow,ResD_$Control.name$);
  181.  
  182. $$endif Control.Default
  183. $$EndLoop Control.type
  184. $$Loop Control.type = Line
  185.     /* Draw a line, $Control.FullName$ */
  186. $$if Control.GrayLine
  187.     PenPat(&qd.gray);                                        /* Set the gray pen pattern */
  188. $$endif Control.GrayLine
  189. $$if Control.LineWidth ! 1
  190.     PenSize($Control.LineWidth$,$Control.LineWidth$);
  191. $$endif Control.LineWidth
  192.     MoveTo($Control.LeftPosition$,$Control.TopPosition$);        /* Horz,vert, Move to starting position */
  193.     LineTo($Control.RightPosition$,$Control.BottomPosition$);    /* Horz,vert, Draw to the ending position */
  194. $$if Control.LineWidth ! 1
  195.     PenSize(1,1);
  196. $$endif Control.LineWidth
  197. $$if Control.GrayLine
  198.     PenPat(&qd.black);                                        /*  Back to default pen pattern  */
  199. $$endif Control.GrayLine
  200.  
  201. $$EndLoop
  202. $$Loop Control.type = StaticText
  203. $$if Control.SpecialText
  204.     /* Draw static text, $Control.FullName$ */
  205. $$if Control.TextColor ! Black
  206.     if (Has.ColorQD)                                        /* See if color QuickDraw is around */
  207.         {
  208.         DrawingColor.red = 0x$Control.RedTextColor$;
  209.         DrawingColor.green = 0x$Control.GreenTextColor$;
  210.         DrawingColor.blue = 0x$Control.BlueTextColor$;
  211.         RGBForeColor(&DrawingColor);                    /* Set the fore color */
  212.         RGBBackColor(&Saved_BackColor);                    /* Set the back color */
  213.         }
  214. $$endif Control.TextColor
  215.     $$if Control.MultipleLine
  216.     SetRect(&tempRect,$Control.LeftPosition$,$Control.TopPosition$,$Control.RightPosition$,$Control.BottomPosition$);
  217.     DrawStaticTextBox(sResD_$Control.name$,&tempRect,$Control.TextAlignment$,$Control.TextSize$,$Control.TextFont$,$Control.TextStyle$);
  218.     $$endif Control.MultipleLine
  219.     $$if Control.SingleLine
  220.     DrawStaticLine(sResD_$Control.name$,$Control.LeftPosition$,$Control.TopPosition$,$Control.TextSize$,$Control.TextFont$,$Control.TextStyle$);
  221.     $$endif Control.SingleLine
  222. $$if Control.TextColor ! Black
  223.     if (Has.ColorQD)                                        /* See if color QuickDraw is around */
  224.         {
  225.         RGBForeColor(&Black_ForeColor);                    /* Set the fore color */
  226.         RGBBackColor(&White_BackColor);                    /* Set the back color */
  227.         }
  228. $$endif Control.TextColor
  229.  
  230. $$endif Control.SpecialText
  231. $$EndLoop
  232. $$Loop Control.type = List
  233.     UpdateTheList(theWindow->visRgn,Rec_$Worksheet.name$.List_$Control.name$,&Rec_$Worksheet.name$.ListRect_$Control.name$,
  234.         $Control.TextSize$,$Control.TextFont$,$Control.TextStyle$,true);
  235.  
  236. $$EndLoop
  237.     TextSize(12);
  238.     TextFont(systemFont);                                /* Select the Font that we want */
  239.     TextFace(0);                                        /* Select the style that we want */
  240.  
  241.     if (Has.ColorQD)                                /* See if color QuickDraw is around */
  242.         {
  243.         RGBForeColor(&Saved_ForeColor);            /* Restore the fore color */
  244.         RGBBackColor(&Saved_BackColor);            /* Restore the back color */
  245.         }                                        /* End of IF */
  246.  
  247.     U_Update_$Worksheet.name$(theWindow);            /* Call the user update routine */
  248.  
  249.     DrawDialog(theWindow);                            /* Draw the rest of the controls */
  250.     SetPort(SavedPort);                            /* Restore the port that we saved at the start */
  251.     }                                            /* End of IF */
  252. }
  253.  
  254. /* ======================================================= */
  255.  
  256. /* Routine: Open_$Worksheet.name$ */
  257. /* Purpose: This procedures purpose is to open this window and set all */
  258. /* of the initial conditions, such as default edit text. */
  259.  
  260. void Open_$Worksheet.name$(void)
  261. {
  262. TEHandle        ThisEditText; 
  263. Rect            tempRect;                            /* Temporary rectangle variable */
  264. short            DType;                                /* Type of dialog item */
  265. Handle            DItem;                                /* Handle to the dialog item */
  266. ControlHandle    CItem;                                /* Control handle */
  267. long            LTemp,LTemp2,theLong;                /* Get selection, temp holding */
  268.  
  269.  
  270. if (Rec_$Worksheet.name$.theDialog == NIL)
  271.     {
  272.     Rec_$Worksheet.name$.theDialog = GetNewDialog(ResD_$Worksheet.name$, NIL,  (WindowPtr)-1 );/* Bring in the dialog resource */
  273.     SetPort(Rec_$Worksheet.name$.theDialog);        /* Prepare to add conditional text */
  274.  
  275.     $$if Worksheet.Center
  276.     tempRect = Rec_$Worksheet.name$.theDialog->portRect;            /* Get the windows position and size */
  277.     $$if Worksheet.CenterHorz
  278.     tempRect.left = ((screenRect.bounds.right - screenRect.bounds.left) - (tempRect.right - tempRect.left)) / 2;    /* Center Horz */
  279.     $$endif Worksheet.CenterHorz
  280.     $$if Worksheet.CenterVert
  281.     tempRect.top = ((screenRect.bounds.bottom - screenRect.bounds.top) - (tempRect.bottom - tempRect.top)) / 3;    /* 1/3 vert */
  282.         if (tempRect.top < 40)                            /* Keep below the menu bar */
  283.         tempRect.top = 40;
  284.     $$endif Worksheet.CenterVert
  285.     MoveWindow(Rec_$Worksheet.name$.theDialog,tempRect.left,tempRect.top,true);
  286.     
  287.     $$endif
  288. $$if ModelessDialog.Movable
  289.     Doing_MovableModal = true;
  290.     
  291. $$endif ModelessDialog.Movable
  292. $$Loop Control.type = Button
  293.     /* Button */
  294.     SetupNormalControl(Rec_$Worksheet.name$.theDialog,ResD_$Control.name$,Rec_$Worksheet.name$.Enable_$Control.name$,0);
  295.  
  296. $$EndLoop Control.type
  297. $$Loop Control.type = Checkbox
  298.     /* Checkbox */
  299.     SetupNormalControl(Rec_$Worksheet.name$.theDialog,ResD_$Control.name$,Rec_$Worksheet.name$.Enable_$Control.name$,
  300.         Rec_$Worksheet.name$.Value_$Control.name$);
  301.  
  302. $$EndLoop Checkbox
  303. $$Loop Control.type = Radio
  304.     /* Radio button */
  305.     SetupNormalControl(Rec_$Worksheet.name$.theDialog,ResD_$Control.name$,Rec_$Worksheet.name$.Enable_$Control.name$,
  306.         Rec_$Worksheet.name$.Value_$Control.name$);
  307.  
  308. $$EndLoop Radio
  309. $$Loop Control.type = List
  310.     /* Make a List */
  311.     Make_A_List(&Rec_$Worksheet.name$.List_$Control.name$,&Rec_$Worksheet.name$.ListRect_$Control.name$,
  312.         Rec_$Worksheet.name$.theDialog,sResD_$Control.name$,$Control.TextSize$,$Control.TextFont$,$Control.TextStyle$,true);
  313.  
  314. $$EndLoop
  315. $$Loop Control.type = HotRect
  316.     /* Draw a Hotspot or Rectangle */
  317.     SetupHotSpot(Rec_$Worksheet.name$.theDialog,ResD_$Control.name$,$Control.MakeHotSpot$,$Control.LineWidth$,
  318.         $Control.ShadowWidth$,sResD_$Control.name$,Rec_$Worksheet.name$.Enable_$Control.name$);
  319.  
  320. $$EndLoop
  321. $$Loop Control.type = EditText
  322.     GetDItem(Rec_$Worksheet.name$.theDialog,ResD_$Control.name$,&DType,&DItem,&tempRect);/* Get the item handle */
  323.     GetIndString(sTemp,sResD_$Control.name$,1);            /* ...Edit text, default value */
  324.     SetIText(DItem,sTemp);                                /* Set the default text string */
  325.     SelIText(Rec_$Worksheet.name$.theDialog,ResD_$Control.name$,0,300);
  326.  
  327. $$EndLoop
  328. $$Loop Control.type = Popup
  329.     SetupPopupMenu(Rec_$Worksheet.name$.theDialog,ResD_$Control.name$,Rec_$Worksheet.name$.Enable_$Control.name$,
  330.         mResD_$Control.name$,Rec_$Worksheet.name$.Value_$Control.name$);
  331.  
  332. $$EndLoop
  333. $$Loop Control.type = Picture
  334. $$if Control.NonGraphic
  335.     /* Draw a picture */
  336.     LTemp = ResD_N_$Control.name$;                        /* Picture ID and resize flag */
  337. $$if Control.ClipPicture
  338.     LTemp = 0x00010000 | LTemp;
  339. $$endif Control.ClipPicture
  340.     SetupTheItem(Rec_$Worksheet.name$.theDialog,ResD_$Control.name$,true,true,
  341.         Rec_$Worksheet.name$.Enable_$Control.name$,false,&tempRect,LTemp,0);
  342.  
  343. $$endif Control.NonGraphic
  344. $$EndLoop
  345. $$Loop Control.type = Palette
  346.     /* Draw a Palette */
  347.     SetupPalette(Rec_$Worksheet.name$.theDialog,ResD_$Control.name$,Rec_$Worksheet.name$.Enable_$Control.name$,
  348.         $Control.NumRows$,$Control.NumColumns$,ResD_N_$Control.name$,$Control.HMethod$);
  349.  
  350. $$EndLoop
  351. $$Loop Control.type = Icon
  352. $$if Control.NonGraphic
  353.     /* Draw an Icon button */
  354.     SetupIconSicn(Rec_$Worksheet.name$.theDialog,ResD_$Control.name$,Rec_$Worksheet.name$.Enable_$Control.name$,
  355.         ResD_N_$Control.name$,ResD_H_$Control.name$);
  356.  
  357. $$endif Control.NonGraphic
  358. $$EndLoop
  359. $$Loop Control.type = Sicn
  360.     /* Draw a Sicn */
  361. $$if Control.Graphic
  362.     SetupIconSicn(Rec_$Worksheet.name$.theDialog,ResD_$Control.name$,Rec_$Worksheet.name$.Enable_$Control.name$,
  363.         ResD_N_$Control.name$,ResD_N_$Control.name$);
  364. $$endif Control.Graphic
  365. $$if Control.NonGraphic
  366.     SetupIconSicn(Rec_$Worksheet.name$.theDialog,ResD_$Control.name$,Rec_$Worksheet.name$.Enable_$Control.name$,
  367.         ResD_N_$Control.name$,ResD_H_$Control.name$);
  368. $$endif Control.NonGraphic
  369.  
  370. $$EndLoop
  371. $$Loop Control.type = UButton
  372.     SetupPlugin(Rec_$Worksheet.name$.theDialog,ResD_$Control.name$,Rec_$Worksheet.name$.Enable_$Control.name$,
  373.         ResD_N_$Control.name$,ResD_H_$Control.name$,sResD_$Control.name$);
  374.  
  375. $$EndLoop
  376. $$Loop Control.type = UToggle
  377.     SetupPlugin(Rec_$Worksheet.name$.theDialog,ResD_$Control.name$,Rec_$Worksheet.name$.Enable_$Control.name$,
  378.         ResD_N_$Control.name$,ResD_H_$Control.name$,sResD_$Control.name$);
  379.  
  380. $$EndLoop
  381. $$Loop Control.type = UGauge
  382.     SetupPlugin(Rec_$Worksheet.name$.theDialog,ResD_$Control.name$,Rec_$Worksheet.name$.Enable_$Control.name$,
  383.         ResD_N_$Control.name$,ResD_H_$Control.name$,sResD_$Control.name$);
  384.     SetupMinMaxValue(Rec_$Worksheet.name$.theDialog,ResD_$Control.name$,$Control.MinScroll$,$Control.MaxScroll$,Rec_$Worksheet.name$.Value_$Control.name$);
  385.  
  386. $$EndLoop
  387. $$Loop Control.type = ScrollBar
  388.     SetupTheItem(Rec_$Worksheet.name$.theDialog,ResD_$Control.name$,true,true,Rec_$Worksheet.name$.Enable_$Control.name$,true,&tempRect,0,0);
  389.     SetupMinMaxValue(Rec_$Worksheet.name$.theDialog,ResD_$Control.name$,$Control.MinScroll$,$Control.MaxScroll$,Rec_$Worksheet.name$.Value_$Control.name$);
  390.  
  391. $$EndLoop
  392.  
  393.     $$Link    Worksheet.Open
  394.  
  395.     U_Setup_$Worksheet.name$(Rec_$Worksheet.name$.theDialog);/* Call the user Open procedure */
  396.  
  397.     ShowWindow(Rec_$Worksheet.name$.theDialog);                /* Open a dialog box */
  398.     SelectWindow(Rec_$Worksheet.name$.theDialog);            /* Lets see it */
  399.     }
  400. else
  401.     SelectWindow(Rec_$Worksheet.name$.theDialog);        /* Lets see it */
  402. }
  403.  
  404. /* ======================================================= */
  405.  
  406. /* Routine: Close_$Worksheet.name$ */
  407. /* Purpose: This procedures purpose is to close this window and clear */
  408. /* the window pointer variable */
  409.  
  410. void Close_$Worksheet.name$(WindowPtr theWindow)
  411. {
  412. Rect    tempRect;                                    /* Temporary rectangle */
  413. short    DType;                                        /* Type of dialog item */
  414. Handle    DItem;                                        /* Handle to the dialog item */
  415.  
  416.  
  417. if ((Rec_$Worksheet.name$.theDialog != NIL) && (theWindow == Rec_$Worksheet.name$.theDialog))/* Only close if it is us and we were open */
  418.     {
  419.  
  420.     U_Close_$Worksheet.name$(theWindow);            /* Call the user close routine */
  421.  
  422.     $$Link    Worksheet.Close
  423.  
  424. $$if ModelessDialog.Movable
  425.     Doing_MovableModal = false;
  426.     
  427. $$endif ModelessDialog.Movable
  428.     DisposDialog(theWindow);                        /* Close on the screen and Flush the dialog out of memory */
  429.     Rec_$Worksheet.name$.theDialog = nil;            /* Make sure our other routines know that we are closed */
  430.     }
  431. }
  432.  
  433. /* ======================================================= */
  434.  
  435. /* Routine: Do_$Worksheet.name$ */
  436. /* Purpose: This procedures purpose is to handle all actions, such as buttons being pressed. */
  437. /* This is the real meat of this unit and is where the code is for acting upon the users actions. */
  438.  
  439. void Do_$Worksheet.name$(EventRecord *theEvent,WindowPtr theWindow,short itemHit)
  440. {
  441. short    Index;                                        /* For looping */
  442. Point    myPt;                                        /* For the local mouse position */
  443. short    DType;                                        /* Type of dialog item */
  444. Handle    DItem;                                        /* Handle to the dialog item */
  445. Rect    tempRect;                                    /* Temporary rectangle */
  446. ControlHandle    CItem;                                /* Control handle */
  447. short    temp;                                        /* temp integer */
  448. short    code;                                        /* temp integer */
  449. short    theSelection;                                /* For Palettes */
  450. Boolean    DoubleClick;                                /* For sensing double clicks in a list */
  451.  
  452.  
  453. Rec_$Worksheet.name$.ExitDialog = false;            /* Do not close the dialog yet */
  454. $$if HasLists
  455. if ((theEvent->what == mouseDown) && (Rec_$Worksheet.name$.theDialog != nil))
  456.     {
  457.     SetPort(Rec_$Worksheet.name$.theDialog);                    /* Set the port to our dialog */
  458.     myPt = theEvent->where;                            /* Get the position where the mouse was pressed */
  459.     GlobalToLocal(&myPt);                            /* Change from global to local location */
  460.  
  461.     $$Loop Control.type = List
  462.     if (PtInRect(myPt,&Rec_$Worksheet.name$.ListRect_$Control.name$))
  463.         ClickInTheList(myPt,theEvent->modifiers,Rec_$Worksheet.name$.List_$Control.name$,$Control.TextSize$,$Control.TextFont$,$Control.TextStyle$,true);
  464.  
  465.     $$EndLoop Control.type
  466.     }
  467. $$endif HasLists
  468.  
  469. if ((Rec_$Worksheet.name$.theDialog != nil)  && (Rec_$Worksheet.name$.theDialog  == theWindow))
  470.     {
  471.     CheckKeysInDialog(theWindow,&DoubleClick,theEvent,&itemHit);
  472.  
  473.     myPt = theEvent->where;                            /* Get the position where the mouse was pressed */
  474.     GlobalToLocal(&myPt);                            /* Change from global to local location */
  475.  
  476.     U_Hit_$Worksheet.name$(theWindow,&itemHit,&Rec_$Worksheet.name$.ExitDialog,theEvent);/* Give the user the itemhit */
  477.  
  478.     if (itemHit > 0)                                /* Skip if user set to zero */
  479.         {
  480.         GetDItem(theWindow, itemHit,&DType,&DItem,&tempRect);/* Get which item was pressed */
  481.         CItem = (ControlHandle)DItem;                /* Change the pointer for getting to the control */
  482.         }
  483.     
  484.     /* Handle it real time */
  485.     $$Loop Control.type = Button
  486.     if (itemHit == ResD_$Control.name$)                /* Handle the Button being pressed */
  487.         {
  488.         $$Link    Control.Select
  489.         $$if Control.ExitDialog
  490.         Rec_$Worksheet.name$.ExitDialog = true;        /* Close this dialog, exit */
  491.         $$endif Control.ExitDialog
  492.         }
  493.  
  494.     $$EndLoop Control.type
  495.     $$Loop Control.type = Checkbox
  496.     if (itemHit == ResD_$Control.name$)                /* Handle the checkbox being pressed */
  497.         {
  498.         temp = GetCtlValue(CItem);                    /* Get the current Checkbox value */
  499.         SetCtlValue(CItem, (temp + 1) & 1);            /* Toggle the value to the opposite */
  500.         Rec_$Worksheet.name$.Value_$Control.name$ = GetCtlValue(CItem);    /* Get the current Checkbox value */
  501.         $$if Control.HasLinks
  502.         if (Rec_$Worksheet.name$.Value_$Control.name$ == 0)
  503.             {
  504.             $$Link    Control.Deselect
  505.             }
  506.         else
  507.             {
  508.             $$Link    Control.Select
  509.             }
  510.         $$endif
  511.         }
  512.  
  513.     $$EndLoop Control.type
  514.     $$Loop Control.type = UButton
  515.     $$if Control.HasLinks
  516.     if (itemHit == ResD_$Control.name$)                /* Handle the Button being pressed */
  517.         {
  518.         $$Link    Control.Select
  519.         }
  520.  
  521.     $$endif
  522.     $$EndLoop Control.type
  523.     $$Loop Control.type = UToggle
  524.     if (itemHit == ResD_$Control.name$)                /* Handle the checkbox being pressed */
  525.         {
  526.         temp = GetCtlValue(CItem);                    /* Get the current Checkbox value */
  527.         SetCtlValue(CItem, (temp + 1) & 1);            /* Toggle the value to the opposite */
  528.         Rec_$Worksheet.name$.Value_$Control.name$ = GetCtlValue(CItem);    /* Get the current Checkbox value */
  529.         $$if Control.HasLinks
  530.         if (Rec_$Worksheet.name$.Value_$Control.name$ == 0)
  531.             {
  532.             $$Link    Control.Deselect
  533.             }
  534.         else
  535.             {
  536.             $$Link    Control.Select
  537.             }
  538.         $$endif
  539.         }
  540.  
  541.     $$EndLoop Control.type
  542.     $$Loop Control.type = Radio
  543.     if (itemHit == ResD_$Control.name$)            /* Handle the Radio being pressed */
  544.         {
  545.         SetCtlValue(CItem,1);
  546.         Rec_$Worksheet.name$.Value_$Control.name$ = 1;    /* Set the current Radio value */
  547.  
  548.         $$Loop RadioGroup
  549.         ClearTheRadio(Rec_$Worksheet.name$.theDialog,ResD_$Control.name$,&Rec_$Worksheet.name$.Value_$Control.name$);
  550.         $$EndLoop RadioGroup
  551.         $$Link    Control.Select
  552.         }
  553.  
  554.     $$EndLoop Control.type
  555.     $$Loop Control.type = HotRect
  556.     $$if Control.HotSpot
  557.     $$if Control.HasLinks
  558.     if (itemHit == ResD_$Control.name$)                /* Handle the HotSpot being pressed */
  559.         {
  560.         $$Link    Control.Select
  561.         }
  562.  
  563.     $$endif
  564.     $$endif Control.HotSpot
  565.     $$EndLoop
  566.     $$Loop Control.type = Popup
  567.     /* Popup */
  568.  
  569.     $$EndLoop
  570.     $$Loop Control.type = Picture
  571.     $$if Control.NonGraphic
  572.     $$if Control.HasLinks
  573.     if (itemHit == ResD_$Control.name$)                /* Handle the Picture being pressed */
  574.         {
  575.         $$Link    Control.Select
  576.         }
  577.  
  578.     $$endif
  579.     $$endif Control.NonGraphic
  580.     $$EndLoop
  581.     $$Loop Control.type = Palette
  582.     /* Palette */
  583.  
  584.     $$EndLoop
  585.     $$Loop Control.type = Icon
  586.     $$if Control.NonGraphic
  587.     $$if Control.HasLinks
  588.     if (itemHit == ResD_$Control.name$)                /* Handle the Icon being pressed */
  589.         {
  590.         $$Link    Control.Select
  591.         }
  592.  
  593.     $$endif
  594.     $$endif Control.NonGraphic
  595.     $$EndLoop
  596.     $$Loop Control.type = Sicn
  597.     $$if Control.NonGraphic
  598.     $$if Control.HasLinks
  599.     if (itemHit == ResD_$Control.name$)                /* Handle the Sicn being pressed */
  600.         {
  601.         $$Link    Control.Select
  602.         }
  603.  
  604.     $$endif
  605.     $$endif Control.NonGraphic
  606.     $$EndLoop
  607.  
  608.     }
  609.  
  610. if (Rec_$Worksheet.name$.ExitDialog)                /* Do the close of the dialog */
  611.     {
  612.     Close_$Worksheet.name$(Rec_$Worksheet.name$.theDialog);
  613.     Rec_$Worksheet.name$.theDialog = nil;                    /* Clear it for future checks */
  614.     }
  615. }
  616.  
  617. /* ======================================================= */
  618. /* ======================================================= */
  619. $$CloseFile
  620. $$EndLoop
  621.  
  622.  
  623.